package com.tiwi.gmbdr.model;

import java.util.ArrayList;
import java.util.List;

import com.tiwi.gmbdr.constant.Global;
import com.tiwi.gmbdr.tools.Tool;

public class Question {

	private int no_soal;
	private String soal;
	private byte[] gambar;
	private String jawaban_a;
	private String jawaban_b;
	private String jawaban_c;
	private String jawaban_d;
	private String jawaban_e;
	private String kunci_jawaban;
	
	
	public Question(){
		
	}
	
	
	// digunakan untuk mengkonvert string dari server ke dalam bentuk object bean
	//1 string akan di bentuk dalam 1 object question
	public Question(String s) {
		if (s == null || "".equals(s.trim()))
			throw new IllegalArgumentException("Invalid question setting from server!");
		
		String[] arrS = Tool.split(s, Global.DELIMETER_DATA);
		if (arrS != null && arrS.length > 0) {
			int idx = 0;
			this.no_soal = Integer.parseInt(arrS[idx++]);
			this.soal = arrS[idx++];
			this.kunci_jawaban = arrS[idx++];
			this.jawaban_a = arrS[idx++];
			this.jawaban_b = arrS[idx++];
			this.jawaban_c = arrS[idx++];
			this.jawaban_d = arrS[idx++];
		}
	}
	
	// mengubah data dari database ke dalam bentuk list pertanyaan.
	public static List<Question> parseToDataList(String questionSetStr, boolean inFlat) {
		if (questionSetStr == null || "".equals(questionSetStr.trim()))
			return null;
		
		List<Question> list = new ArrayList<Question>();
		String[] questionSet = Tool.split(questionSetStr, Global.DELIMETER_ROW);
		if (questionSet != null && questionSet.length > 0) {
//			int idx = 0;
			for (String s : questionSet) {
				Question bean = new Question(s);
				//bean.setQuestionOrder(idx++);
				list.add(bean);
			}
		}		
		
		return list;
	}
	
	
	public int getNo_soal() {
		return no_soal;
	}
	public void setNo_soal(int no_soal) {
		this.no_soal = no_soal;
	}
	public String getSoal() {
		return soal;
	}
	public void setSoal(String soal) {
		this.soal = soal;
	}
	public byte[] getGambar() {
		return gambar;
	}
	public void setGambar(byte[] gambar) {
		this.gambar = gambar;
	}
	public String getJawaban_a() {
		return jawaban_a;
	}
	public void setJawaban_a(String jawaban_a) {
		this.jawaban_a = jawaban_a;
	}
	public String getJawaban_b() {
		return jawaban_b;
	}
	public void setJawaban_b(String jawaban_b) {
		this.jawaban_b = jawaban_b;
	}
	public String getJawaban_c() {
		return jawaban_c;
	}
	public void setJawaban_c(String jawaban_c) {
		this.jawaban_c = jawaban_c;
	}
	public String getJawaban_d() {
		return jawaban_d;
	}
	public void setJawaban_d(String jawaban_d) {
		this.jawaban_d = jawaban_d;
	}
	public String getJawaban_e() {
		return jawaban_e;
	}
	public void setJawaban_e(String jawaban_e) {
		this.jawaban_e = jawaban_e;
	}
	public String getKunci_jawaban() {
		return kunci_jawaban;
	}
	public void setKunci_jawaban(String kunci_jawaban) {
		this.kunci_jawaban = kunci_jawaban;
	}
	
	
}
